package com.deryun.tyl.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Service;

import com.deryun.tyl.bean.Publicity;
import com.deryun.tyl.bean.User;
import com.deryun.tyl.dao.impl.PublicityDaoImpl;

@Service("publicityServiceImpl")
public class PublicityServiceImpl {
	
	@Resource(name="publicityDaoImpl")
	private PublicityDaoImpl publicityDaoImpl;
	
	public int addPublicity(HttpServletRequest request,Publicity publicity){
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		publicity.setPublishDate(df.format(new Date()));
		publicity.setPublishMan(((User)request.getSession().getAttribute("user")).getContactMan());
		publicity.setPublishUserId(((User)request.getSession().getAttribute("user")).getId().toString());
		return publicityDaoImpl.addPublicity(publicity);
	}
	
	public List<Publicity> getAllPublicity(){
		return publicityDaoImpl.getAllPublicity();
	}
	
	public List<Publicity> getUserPublicity(String publishUserId){
		return publicityDaoImpl.getUserPublicity(publishUserId);
	}
	
	public int deletePublicity(int id){
		return publicityDaoImpl.deletePublicity(id);
	}
	
	public int modifyPublicity(Publicity publicity){
		return publicityDaoImpl.modifyPublicity(publicity);
	}
	
	public Publicity getPublicityById(int id){
		return publicityDaoImpl.getPublicityById(id);
	}
	
	public int setResult(Publicity publicity){
		return publicityDaoImpl.setResult(publicity);
	}
}
